var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2AudioManager = require("AudioManager");
var $2BulletMgr = require("BulletMgr");
var $2BundleManager = require("BundleManager");
var $2ZombieMgr = require("ZombieMgr");
var $2SceneStage = require("SceneStage");
var $2KDefine = require("KDefine");
var $2MyUtils = require("MyUtils");
var $2BulletBase = require("BulletBase");
var $2PlantBase = require("PlantBase");
var g = cc._decorator.ccclass;
var def_Plant6 = /* */function (_u$default3) {
  babel_inherits(p, _u$default3);
  var _super69 = babel_createSuper(p);
  function p() {
    babel_classCallCheck(this, p);
    return _super69.apply(this, arguments);
  }
  babel_createClass(p, [{
    key: "shoot",
    value: function shoot() {
      var _this150 = this;
      var e = this;
      var t = this.getZombie();
      if (null != t) {
        if (0 == this.remainCD) {
          var _a37 = this.dragon.setAnimation(0, "dazhao", false);
          var _n36 = 0;
          this.dragon.setCompleteListener(function () {
            e.setState($2KDefine.State.wait);
            _this150.attackTimes += _this150.attackCD;
            _this150.remainCD = _this150.skillCD;
          });
          this.dragon.setTrackEventListener(_a37, function (e, a) {
            if ("dazhao" == a.data.name) {
              t.x += 80 * _n36;
              _this150.attack(t, true);
            }
          });
        } else {
          this.dragon.setCompleteListener(function () {
            e.setState($2KDefine.State.wait);
          });
          this.attackTimes += this.attackCD;
          var _a38 = this.dragon.setAnimation(0, "gongji", false);
          this.dragon.setTrackEventListener(_a38, function (e, a) {
            "gongji" == a.data.name && _this150.attack(t);
          });
        }
      } else {
        e.setState($2KDefine.State.wait);
      }
    }
  }, {
    key: "attack",
    value: function attack(e) {
      var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
      var a;
      var n = new cc.Vec2(this.node.getPosition().x + this.shootPo.x, this.node.getPosition().y + this.shootPo.y);
      var l = new cc.Vec2(n.x + (e.x - n.x) / 2, n.y + 400);
      if (t) {
        a = $2BulletMgr.default.instance().getItem(this.skillbullet, this.damage, this.hitSound, this.hitSoundVolume).node;
        $2AudioManager.default.instance.playEffect(this.skillSound, this.skillSoundVolume);
      } else {
        $2AudioManager.default.instance.playEffect(this.shootSound, this.shootSoundVolume);
        a = $2BulletMgr.default.instance().getItem(this.bulletId, this.damage, this.hitSound, this.hitSoundVolume).node;
      }
      a.angle = 30;
      a.getComponent(cc.CircleCollider).enabled = false;
      a.parent = $2SceneStage.default.instance.groudNode;
      a.setPosition(n);
      a.zIndex = $2KDefine.ZIndex.bullet;
      a.opacity = 255;
      cc.tween(a).parallel(cc.tween(a).bezierTo(1.5 / this.attackSpeed, n, l, e), cc.tween(a).to(1.5 / this.attackSpeed, {
        angle: 720
      })).call(function () {
        var e = a.getChildByName("bulletEffect").getComponent(sp.Skeleton);
        a.getComponent(cc.CircleCollider).enabled = true;
        a.getChildByName("bulletEffect").active = true;
        a.getComponent(cc.Sprite).enabled = false;
        e.skeletonData = $2BundleManager.default.instance.getBundleRes("Spine", "effect/" + a.getComponent($2BulletBase.default).bulletEffect + "/" + a.getComponent($2BulletBase.default).bulletEffect, sp.SkeletonData);
        e.setAnimation(0, "newAnimation", false);
        e.setCompleteListener(function () {
          a.getChildByName("bulletEffect").active = false;
          $2BulletMgr.default.instance().removeBullet(a.getComponent($2BulletBase.default));
          e.setCompleteListener(null);
        });
      }).start();
    }
  }, {
    key: "getZombie",
    value: function getZombie() {
      var _this151 = this;
      var e = 99999;
      var t = null;
      $2ZombieMgr.default.instance().zombieInRow[this.row].forEach(function (a) {
        if (_this151.node.x < a.node.x) {
          var _n37 = $2MyUtils.MyUtils.getDis(_this151.node.x, _this151.node.y, a.node.x, a.node.y);
          if (_n37 < e) {
            e = _n37;
            t = a.node;
          }
        }
      });
      if (null == t) {
        return null;
      } else {
        return new cc.Vec2(t.getPosition().x - 25, t.getPosition().y);
      }
    }
  }]);
  return p;
}($2PlantBase.default);
def_Plant6 = cc__decorate([g], def_Plant6);
exports.default = def_Plant6;